﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommonClasses
{
    public class BJHand : Hand
    {
        private int ace_count;

        public new int Total;
        public string name;

        public new int MaxCards = 5;

        private void _calculateForAce()
        {           
            while (ace_count > 0 && Total > 21)
            {
                Total -= 10;
                ace_count -= 1;
            }            
        }

        public override void calculate_total()
        {

            Total = 0;
            ace_count = 0;

            foreach (Card c in CardsOnHand)
            {
                if (c.FaceDown == false)
                {
                    Total += c.FaceValue;
                    if (c.Rank == "a")
                    {
                        ace_count++;
                    }
                }                
            }

            if (ace_count > 0)
            {
                _calculateForAce();
            }                 
        }

        public ObservableCollection<Card> CardsInPlay()
        {
            ObservableCollection<Card> cardsInPlay = new ObservableCollection<Card>();
            foreach (Card c in CardsOnHand)
            {
                if (c.FaceDown == true)
                {
                    c.ImageInUse = c.FDImage;
                }
                else
                {
                    c.ImageInUse = c.Image;
                }
                cardsInPlay.Add(c);
            }
            return cardsInPlay;
        }
    }
}
